Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply memoization in get_all_universes #2995

Merged
merged 6 commits into from
May 24, 2024

Conversation

pshriwise
Copy link
Contributor

Description

While working on a model with TRISO compacts, @aprilnovak noticed that the Geometry.get_all_universes method was taking a long time (3+ hours) -- preplexing as the get_all_cells call was taking less than a second.

It turns out that we weren't using the memoization objects we have in place for this call/chain-of-calls in the geometry objects. This PR adds the use of memoization for that call.

I haven't added any tests here as the set of tests we have in place exercises these methods significantly -- they should just be faster now.

Checklist

  • I have performed a self-review of my own code
  • I have run clang-format (version 15) on any C++ source files (if applicable)
  • I have followed the style guidelines for Python source files (if applicable)
  • I have made corresponding changes to the documentation (if applicable)
  • I have added tests that prove my fix is effective or that my feature works (if applicable)

@pshriwise pshriwise requested a review from paulromano May 9, 2024 16:56
@pshriwise
Copy link
Contributor Author

pshriwise commented May 9, 2024

One note here is that the pattern:

if memo and self in memo:
    return {}

was pre-existing in other calls using memoization. I stuck with this here for consistency even though this might be more explicit and better:

if memo is not None and self in memo:
    return {}

Happy to update this across the board at the reviewer's request.

@pshriwise pshriwise changed the title Speedy univ Apply memoization in get_all_universes May 10, 2024
Copy link
Contributor

@paulromano paulromano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this @pshriwise! Two things seem a little weird to me in the implementation but hopefully it's easy to fix:

openmc/universe.py Outdated Show resolved Hide resolved
openmc/geometry.py Outdated Show resolved Hide resolved
Copy link
Contributor

@paulromano paulromano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @pshriwise!

@paulromano paulromano enabled auto-merge (squash) May 24, 2024 22:38
@paulromano paulromano merged commit 25e47de into openmc-dev:develop May 24, 2024
17 checks passed
church89 pushed a commit to openmsr/openmc that referenced this pull request Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants